home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14227 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  56 lines

  1. Path: liberty.b23a.ingr.com!dpmikese
  2. From: dpmikese@ingr.com (Dave Mikesell)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to use assert( )
  5. Date: Fri, 12 Apr 1996 12:37:50
  6. Organization: Intergraph
  7. Message-ID: <dpmikese.14.005EA7C0@ingr.com>
  8. References: <4kc3k7$dur@orion.cybercom.net> <316be48b.3354928@news.netvision.net.il> <4kiirb$hll@sparcserver.lrz-muenchen.de> <smryanDpqBv7.E56@netcom.com>
  9. NNTP-Posting-Host: liberty.b23a.ingr.com
  10. X-Newsreader: Trumpet for Windows [Version 1.0 Rev B final beta #4]
  11.  
  12. In article <smryanDpqBv7.E56@netcom.com> smryan@netcom.com (@#$%!?!) writes:
  13. >Newsgroups: comp.lang.c
  14. >Path: b10.b10.ingr.com!news.ingr.com!news.msfc.nasa.gov!newsfeed.internetmci.com!howland.reston.ans.net!ix.netcom.com!netcom.com!smryan
  15. >From: smryan@netcom.com (@#$%!?!)
  16. >Subject: Re: How to use assert( )
  17. >Message-ID: <smryanDpqBv7.E56@netcom.com>
  18. >Organization: The Programmer formerly known as S M Ryan
  19. >X-Newsreader: TIN [version 1.2 PL1]
  20. >References: <4kc3k7$dur@orion.cybercom.net> <316be48b.3354928@news.netvision.net.il> <4kiirb$hll@sparcserver.lrz-muenchen.de>
  21. >Date: Fri, 12 Apr 1996 03:18:43 GMT
  22. >Lines: 14
  23. >Sender: smryan@netcom21.netcom.com
  24.  
  25.  
  26. >: The end user should never see the output of an assertion in an ideal
  27. >: world. One reason for this is that a final build should be translated 
  28. >: with NDEBUG defined. The other (more optimistic) reason is, that all
  29. >: possible problems that make an assertion fail should have been
  30. >: detected during testing.
  31.  
  32. >It is preferable to have the program fail mysteriously for the customer
  33. >with possibly the only opportunity to diagnose it gone.
  34.  
  35. Not if you build in user-level debugging.  For instance, your code could
  36. check for the existence of an environment variable defined in the user's
  37. environment - if it's there, you could write debug info somewhere that 
  38. the user could get to and relay it to you.  I prefer this method to firing
  39. an assertion and aborting the program.  Of course, you could write your own
  40. assert macro and function that doesn't abort...it's not that hard:
  41.  
  42. #ifdef DEBUG
  43. #define ASSERT(expr) if (expr) {} else _Assert(__FILE__, __LINE__)
  44. #else
  45. #define ASSERT(expr)
  46. #endif
  47.  
  48. void _Assert(char *file, unsigned line)
  49.     {
  50.     fprintf(stderr, "\nAssertion failed: %s, line %d\n", file, line);
  51.     }
  52.  
  53. --
  54. Dave M.
  55.  
  56.